package com.ruoyi.sl.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.sl.domain.SlApprentice;
import com.ruoyi.sl.service.ISlModuleService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sl.domain.SlWm;
import com.ruoyi.sl.service.ISlWmService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 出工方式Controller
 * 
 * @author admin
 * @date 2024-06-03
 */
@RestController
@RequestMapping("/sl/wm")
public class SlWmController extends BaseController
{
    @Autowired
    private ISlWmService slWmService;

    @Autowired
    private ISlModuleService slModuleService;
    /**
     * 查询出工方式列表
     */
    @PreAuthorize("@ss.hasPermi('sl:wm:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlWm slWm)
    {
        startPage();
        List<SlWm> list = slWmService.selectSlWmList(slWm);
        return getDataTable(list);
    }

    /**
     * 导出出工方式列表
     */
    @PreAuthorize("@ss.hasPermi('sl:wm:export')")
    @Log(title = "出工方式", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlWm slWm)
    {
        List<SlWm> list = slWmService.selectSlWmList(slWm);
        ExcelUtil<SlWm> util = new ExcelUtil<SlWm>(SlWm.class);
        util.exportExcel(response, list, "出工方式数据");
    }

    /**
     * 获取出工方式详细信息
     */
    @PreAuthorize("@ss.hasPermi('sl:wm:query')")
    @GetMapping(value = { "/", "/{wmId}" })
    public AjaxResult getInfo(@PathVariable(value = "wmId", required = false) Long wmId)
    {
        AjaxResult ajax = AjaxResult.success();
        ajax.put("modules", slModuleService.selectModuleAll());
        if (StringUtils.isNotNull(wmId))
        {
            SlWm slWm = slWmService.selectSlWmByWmId(wmId);
            ajax.put(AjaxResult.DATA_TAG, slWm);
        }
        return ajax;
        //return success(slWmService.selectSlWmByWmId(wmId));
    }

    /**
     * 新增出工方式
     */
    @PreAuthorize("@ss.hasPermi('sl:wm:add')")
    @Log(title = "出工方式", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlWm slWm)
    {
        slWm.setCreateBy(getUsername());
        return toAjax(slWmService.insertSlWm(slWm));
    }

    /**
     * 修改出工方式
     */
    @PreAuthorize("@ss.hasPermi('sl:wm:edit')")
    @Log(title = "出工方式", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlWm slWm)
    {
        slWm.setUpdateBy(getUsername());
        return toAjax(slWmService.updateSlWm(slWm));
    }

    /**
     * 删除出工方式
     */
    @PreAuthorize("@ss.hasPermi('sl:wm:remove')")
    @Log(title = "出工方式", businessType = BusinessType.DELETE)
	@DeleteMapping("/{wmIds}")
    public AjaxResult remove(@PathVariable Long[] wmIds)
    {
        return toAjax(slWmService.deleteSlWmByWmIds(wmIds));
    }
}
